package jsyf.oa.web.wechat.service_company;

import com.alibaba.fastjson.JSONObject;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wechat.service_company.TokenFacade;

@Api(value = "企业号接口", description = "企业号接口")
@Controller
@RequestMapping("/token")
public class TokenController {
    @Resource
    private TokenFacade tokenFacade;

    @ApiOperation(
            value = "获取全部员工",
            notes = "获取全部员工",
            httpMethod = "GET",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "无参数", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getAllStaff.json", method = RequestMethod.GET)
    public void getAllStaff(HttpServletResponse response) {
        JSONObject records = tokenFacade.getAllStaff();
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("获取数据错误"));
        }
    }

    @ApiOperation(
            value = "更新员工信息",
            notes = "更新员工信息",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{ \"userId\": \"zhangsan\", \"name\": \"张三\",  \"tel\": \"15913215421\" }", dataType = "String", paramType = "body")
    @RequestMapping(value = "/updateStaff.json", method = RequestMethod.POST)
    public void updateStaff(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = tokenFacade.updateStaff(jsonData);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("获取数据错误"));
        }
    }

    @ApiOperation(
            value = "发送文字消息",
            notes = "发送文字消息",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    @RequestMapping(value = "/sendTextMsg.json", method = RequestMethod.POST)
    public void sendTextMsg(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = tokenFacade.sendTextMsg(jsonData);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("获取数据错误"));
        }
    }

    @ApiOperation(
            value = "员工入职",
            notes = "员工入职",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{ \"userId\": \"zhangsan\", \"name\": \"张三\",  \"tel\": \"15913215421\" }", dataType = "String", paramType = "body")
    @RequestMapping(value = "/entry.json", method = RequestMethod.POST)
    public void entry(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = tokenFacade.entry(jsonData);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("获取数据错误"));
        }
    }

    @ApiOperation(
            value = "员工离职",
            notes = "员工离职",
            httpMethod = "GET")
    @ApiImplicitParam(name = "userId", value = "zhangsan", dataType = "String", paramType = "query")
    @RequestMapping(value = "/leave.json", method = RequestMethod.GET)
    public void leave(HttpServletResponse response, @RequestParam String userId) {
        JSONObject records = tokenFacade.leave(userId);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("获取数据错误"));
        }
    }


}
